package com.qys.livesMall.shop.controller;

import com.esotericsoftware.minlog.Log;
import com.qys.livesMall.shop.enums.ShopEventTypeEnum;
import com.qys.livesMall.shop.event.ShopEvent;
import com.qys.livesMall.shop.event.shop.pojo.OpenShopEventPojo;
import com.qys.livesMall.shop.modal.entity.ShopEventInfo;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @menu TestController
 * @date 2023/11/03 11:59
 */
@RestController
@RequestMapping("/shop/test")
public class TestController {

    @Resource
    private ApplicationContext applicationContext;

    @PostMapping("/add")
    public void add(){
        try{
            applicationContext.publishEvent(new ShopEvent(ShopEventInfo.builder()
                    .shopId(System.currentTimeMillis())
                    .eventType(ShopEventTypeEnum.SHOP_OPEN_SUCCESS.getType())
                    .paramObj(OpenShopEventPojo.builder()
                            .userId(111l)
                            .build()
                    ).build())
            );
        } catch (Exception e) {
            Log.info("监听异常,:", e);
        }
    }

}

